/**
 * 编辑用来显示商场楼层
 */
(function ($, undefined) {
    $.fn.floorShow = function (options) {
        var settings = {};
        if (options) {
            $.extend(settings, options);
        }
        var self = this, url;
        $(self).click(function () {
            $('a.mall').parent().parent().removeClass('info');
            $(this).parent().parent().addClass('info');
            //清空品牌信息
            $("#brands").html('');
            url = setting.app + settings.url + $(this).data('mid');
            $.getJSON(url, function (data) {
                if (data.status == 1) {
                    $(settings.floors).html(data.data);
                    $(settings.floors).show();
                    $('a.phone').editorPhone();
                    $('a.show_add').addPhone();
                } else {
                    $(settings.floors).hide();
                }
            });
        });
    };
}(jQuery));
/**
 * 编辑用来显示柜台
 */
(function ($, undefined) {
    $.fn.floorBrandShow = function (options) {
        var settings = {};
        if (options) {
            $.extend(settings, options);
        }
        var self = this, url;
        $(self).click(function () {
            $(settings.floors).html('Loading...');
            $('a.floor').parent().parent().removeClass('info');
            $(this).parent().parent().addClass('info');
            url = setting.app + settings.url + $(this).data('fid');
            $.getJSON(url, function (data) {
                if (data.status == 1) {
                    $(settings.floors).html(data.data);
                    $(settings.floors).show();
                    $('a.phone').editorPhone();
                    $('a.show_add').addPhone();
                } else {
                    $(settings.floors).hide();
                }
            });
        });
    };
}(jQuery));
/**
 * 任务延期
 */
(function ($, undefined) {
    $.fn.activityExt = function (options) {
        var settings = {url:"/TaskManage/activityExtension/id/" };
        if (options) {
            $.extend(settings, options);
        }
        $(this).click(function () {
            $.getJSON(setting.app + settings.url + $(this).data("tid"), function (data) {
                if (data.status == 1) {
                    createBox(data.data);
                } else {
                    alert(data.data);
                }
            });
        });
    };
}(jQuery));
/**
 * 获取号码信息
 */
(function ($, undefined) {
    $.fn.editorPhone = function (options) {
        var settings = {url:"/Task/Phone/getPhones/"};
        if (options) {
            $.extend(settings, options);
        }
        $(this).unbind('click');
        $(this).click(function () {
            $('a.phone').parent().parent().removeClass('success');
            $(this).parent().parent().addClass('success');
            var mid = $(this).data('mid');
            var fid = $(this).data('fid');
            var bid = $(this).data('bid');
            var url = settings.url + "mid/" + mid;
            if (fid) {
                url = url + "/fid/" + fid;
            }
            if (bid) {
                url = url + "/bid/" + bid;
            }
            $.getJSON(setting.app + url, function (data) {
                if (data.status == 1) {
                    $("#phones").html(data.data);
                    $("#phones").show();
                } else {
                    $("#phones").hide();
                }
            });
        });
    };
}(jQuery));
//修改电话号码
(function ($, undefined) {
    $.fn.editPhone = function (options) {
        var settings = {url:"/Task/Phone/edit/"};
        if (options) {
            $.extend(settings, options);
        }
        $(this).unbind('click');
        $(this).click(function () {
            var id = $(this).data("pid");
            $.getJSON(setting.app + '/phone/update/' + id, function (data) {
                if (data.status == 1) {
                    createBox(data.data);
                    $("a.button").addClass('btn');
                } else {
                    createBox(data);
                }
            });
        });
    };
}(jQuery));
//编辑添加商场相关号码
(function ($, undefined) {
    $.fn.addPhone = function (options) {
        var settings = {
            addHtml:'',
            url:setting.app + '/phone',
            input_name:"input[id=name]",
            input_phone:"input[id=phone]",
            input_remark:"input[id=remark]",
            phone_do_add:'a#doAddPhone'
        };
        if (options) {
            $.extend(settings, options);
        }
        settings.addHtml = setting.addHtml;
        // 执行赋值操作
        var mid, fid, bid, add_form_html, name, phone, remark;
        // 获取当前变量中值 和 设置隐藏指
        var getObjVals = function (obj) {
            mid = $(obj).data("mid");
            fid = $(obj).data("fid");
            bid = $(obj).data("bid");
            mid = mid ? mid : 0;
            fid = fid ? fid : 0;
            bid = bid ? bid : 0;
        };
        // 添加号码
        var doAdd = function (obj, mid, fid, bid, name, phone, remark) {
            $.getJSON(settings.url + '/add?mid=' + mid + '&fid=' + fid + '&bid=' + bid
                + "&name=" + name + "&phone=" + phone + "&remark=" + remark, function (data) {
                if (data.status) {
                    // 执行添加后显示
                    closeBox();
                } else {
                    alert(data.info + data.data);
                }
            });
        };
        // 获取应参数
        var getVals = function () {
            name = $(settings.input_name).val();
            phone = $(settings.input_phone).val();
            remark = $(settings.input_remark).val();
            remark = remark ? remark : '';

        };
        $(this).click(function () {
            getObjVals(this);
            createBox(settings.addHtml);
            $(settings.phone_do_add).click(function () {
                getVals();
                doAdd(this, mid, fid, bid, name, phone, remark);
            });
        });
    };
}(jQuery));
//编辑添加任务
(function ($, undefined) {
    $.fn.editorAddTask = function (options) {
        var settings = {url:"/TaskManage/add"};
        if (options) {
            $.extend(settings, options);
        }
        $(this).unbind('click');
        $(this).click(function () {
            var mid = $(this).data('mid');
            var fid = $(this).data('fid');
            var bid = $(this).data('bid');
            if (mid && fid && bid) {
                $.getJSON(setting.app + settings.url + '/mid/' + mid + '/fid/'
                    + fid + '/bid/' + bid, function (data) {
                    if (data.status) {
                        createBox(data.data);
                        $('.add_rw').addClass('btn btn-primary').val('添加')
                    } else {
                        alert(data.data);
                    }
                });
            }
        });
    };
}(jQuery));
//编辑修改任务
(function ($, undefined) {
    $.fn.editorUpdateTask = function (options) {
        var settings = {url:"/TaskManage/update/id/"};
        if (options) {
            $.extend(settings, options);
        }
        $(this).unbind('click');
        $(this).click(function () {
            var tid = $(this).data('tid');
            if (tid) {
                $.getJSON(setting.app + '/TaskManage/update/id/' + tid,
                    function (data) {
                        if (data.status) {
                            createBox(data.data);
                        } else {
                            alert(data.data);
                        }
                    });
            }
        });
    };
}(jQuery));